package ebj.common.redis.helper;

import java.util.MissingResourceException;
import java.util.ResourceBundle;

import org.apache.log4j.Logger;

import com.google.common.base.Strings;

public class Configuration {
	private Logger logger = Logger.getLogger(Configuration.class);

	private String propertiesFileName = "config";
	private ResourceBundle resourceBundle;

	public static Configuration getInstance() {
	    return new Configuration();
    }
	public static Configuration getInstance(String fileName) {
		return new Configuration(fileName);
	}
	public static Configuration getInstance(String filePath, String fileName) {
		return new Configuration(filePath, fileName);
	}
	
	private Configuration() {
		resourceBundle = ResourceBundle.getBundle(propertiesFileName);
	}
	
	private Configuration(String filePath, String fileName) {
		if (!Strings.isNullOrEmpty(filePath) || !Strings.isNullOrEmpty(fileName)) {
	        this.setPropertiesFileName(filePath + fileName);
        }
		resourceBundle = ResourceBundle.getBundle(propertiesFileName);
	}
	
	private Configuration(String fileName) {
		if (!Strings.isNullOrEmpty(fileName)) {
			this.setPropertiesFileName(fileName);
        }
		resourceBundle = ResourceBundle.getBundle(propertiesFileName);
	}

	public String getProperty(String keyWord) {
		String value = "";
		if (Strings.isNullOrEmpty(keyWord)) {
			return "";
		}
		
		try {
			value = resourceBundle.getString(keyWord);
		} catch (MissingResourceException e) {
			logger.error("", e);
		}
		return value;
	}

	private void setPropertiesFileName(String propertiesFileName) {
		this.propertiesFileName = propertiesFileName;
	}
	public String getPropertiesFileName() {
		return propertiesFileName;
	}
}
